package kaka.controls.paging
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import kaka.event.PageEvent;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class PagingProxy extends EventDispatcher
	{
		//总页数
		private var _totalPageNum:int=10;
		//每页显示多少条
		private var _pageSize:int=15;
		//当前页数
		private var _currentPageNum:int=1;
		//下一页开始条数
		private var _nextStartNum:int=0;
		//总条数
		private var _totalNum:int=0;
		private var _serviceName:String;
		private var _methodName:String;
		public function PagingProxy(target:IEventDispatcher=null)
		{
			super(target);
		}

		public function get nextStartNum():int
		{
			return _nextStartNum;
		}
		public function setNextStartNum(value:int):void
		{
			_nextStartNum=value;
		}
		public function getTotalNum():int
		{
			return _totalNum;
		}
		
		public function setTotalNum(value:int):void
		{
			_totalNum = value;
			if(_totalNum%_pageSize==0)
			{
				_totalPageNum=_totalNum/_pageSize;
			}
			else
			{
				_totalPageNum=int(_totalNum/_pageSize)+1;
			}
			trace(_totalNum);
			trace(_totalPageNum);
			 
		}
		public function get currentPageNum():int
		{
			return _currentPageNum;
		}

		public function set currentPageNum(value:int):void
		{
			_currentPageNum = value;
			//_nextStartNum=_currentPageNum*_pageSize+1;
			//trace(_nextStartNum);
		}

		public function get pageSize():int
		{
			return _pageSize;
		}

		public function set pageSize(value:int):void
		{
			_pageSize = value;
		}
		public function get totalPageNum():int
		{
			//trace("总页数:"+_totalPageNum);
			return _totalPageNum;
		}

		public function set totalPageNum(value:int):void
		{
			_totalPageNum = value;
		}

		/**
		 * @override
		 **/
		public function loadData():void
		{
			
		}
		protected function onResult(e:ResultEvent):void
		{
			var evt:PageEvent=new PageEvent(PageEvent.LOAD_COMPLETE,e.result);
			dispatchEvent(evt);
		}
		protected function onFault(e:FaultEvent):void
		{
			var evt:PageEvent=new PageEvent(PageEvent.LOAD_FAULT,e.fault);
			dispatchEvent(evt);
			Alert.show(e.fault.faultString);
		}
		public function get serviceName():String
		{
			return _serviceName;
		}

		public function set serviceName(value:String):void
		{
			_serviceName = value;
		}

		public function get methodName():String
		{
			return _methodName;
		}

		public function set methodName(value:String):void
		{
			_methodName = value;
		}


	}
}